package thread.method;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-03-06
 * Time:16:39
 */
public class Method3 {
    /*
    用户线程:也叫工作线程,线程的结束由当前线程的任务执行完或用通知的方式结束
    守护线程:一般是为工作线程服务
            当所有的用户线程结束,守护线程自动结束
            例:垃圾回收机制
    ========================================
    Java设置守护线程的方式:
    void setDaemon(boolean on) 设置当前线程为守护线程
     */
    public static void main(String[] args) throws InterruptedException {
        T3 t3 = new T3();
        t3.setDaemon(true);
        t3.start();
        for (int i = 0; i < 10; i++) {
            System.out.println("发工资第" + (i + 1) + "天");
            Thread.sleep(200);
        }
    }
}
class T3 extends Thread{
    @Override
    public void run() {
        int count = 0;
        while (true) {
            System.out.println("挖矿第" + (++count) + "天");
            try {
                sleep(200);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
